package org.sxp.common.utils;

import com.alibaba.fastjson.JSONObject;
import org.springframework.beans.BeanUtils;

import java.util.List;

/**
 * 
 * @Author shenxingping
 * @Date 2021/1/22
 */
public class XPBeanUtils {
    public static  <T> T copyBean(Object source, Class<T> target) throws Exception{
        T targetObj = target.newInstance();
        if(source != null) {
            BeanUtils.copyProperties(source, targetObj);
        }
        return targetObj;
    }

    public static <T> List<T> copyBeanList(List<?> source, Class<T> target){
        String result = JSONObject.toJSONString(source);
        return (List<T>) JSONObject.parseArray(result, target);
    }
}
